package org.zlw.core.request;

import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.QueryStringDecoder;
import io.netty.handler.codec.http.cookie.Cookie;
import lombok.Getter;
import org.asynchttpclient.Request;
import org.asynchttpclient.RequestBuilder;

import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

/**
 * 网关请求对象
 */
public class GatewayRequest implements IGateWayRequest{
//定义网关自身属性
    /**
     * 服务唯一ID
     */
    @Getter
    private final  String uniqueId;
    /**
     * 进入网关开始时间
     */
    @Getter
    private final long beginTime;
    /**
     * 进入网关结束时间
     */
    @Getter
    private final long endTime;
    /**
     * 字符集
     */
    @Getter
    private final Charset charset;

    //网关请求的时候，请求对象里面也要包括的客户端的IP：流控，黑白名单
    /**
     * 客户端ip
     */
    @Getter
    private final String clientIp;

    /**
     * 服务端主机名
     */
    @Getter
    private final String host;
    /**
     * 服务端的请求路径 .com/xxx/xx/xx
     * 不包括请求参数
     */
    @Getter
    private final String path;
    /**
     * 统一资源标识符.com/xxx/xx/xx?attr=1&attr2=2
     */
    @Getter
    private final String uri;
    /**
     * 请求方式定义
     * post,get,put
     * @param host
     */
    @Getter
    private final HttpMethod httpMethod;

    /**
     * 请求格式
     * @param host
     */
    @Getter
    private final HttpMethod contentType;

    /**
     * 请求头
     * Cookie放在里面的
     * @param host
     */
    @Getter
private final HttpHeaders httpHeaders;
    /**
     * 参数解析器
     */
    @Getter
    private final QueryStringDecoder queryStringDecoder;
    /**
     * 是否合法的请求
     */
    @Getter
    private final FullHttpRequest fullHttpRequest;


    //Post方式怎么拿到
    /**
     * 请求体
     */
    private String body;

    /**
     *
     */
    private Map<String,Cookie> cookieMap;
    /**
     * Post请求参数
     */
    private Map<String, List<String>> postParamters;

    /**
     * 可修改协议，默认Http://
     * @param host
     */
    private  String modifyScheme;
    /**
     * 可修改主机名
     * @param host
     */
    private  String modifyHost;

    /**
     * 可修改路径
     * @param host
     */
    private  String modifyPath;


//    提供一个方法，传进是这个样子，构建请求下一个服务器
    /**
     * 构建下游请求时候的http构建器
     */
    private  final RequestBuilder requestBuilder;
    //不变的构造起来
    public GatewayRequest(String uniqueId, long beginTime,
                          long endTime, Charset charset,
                          String clientIp, String host,
                          String path, String uri,
                          HttpMethod httpMethod, HttpMethod contentType,
                          HttpHeaders httpHeaders,
                          QueryStringDecoder queryStringDecoder,
                          FullHttpRequest fullHttpRequest, RequestBuilder requestBuilder) {
        this.uniqueId = uniqueId;
        this.beginTime = beginTime;
        this.endTime = endTime;
        this.charset = charset;
        this.clientIp = clientIp;
        this.host = host;
        this.path = path;
        this.uri = uri;
        this.httpMethod = httpMethod;
        this.contentType = contentType;
        this.httpHeaders = httpHeaders;
        this.queryStringDecoder = queryStringDecoder;
        this.fullHttpRequest = fullHttpRequest;
        this.requestBuilder = requestBuilder;
    }





    @Override
    public void setModifyHost(String host) {

    }

    @Override
    public String getModifyHost() {
        return null;
    }

    @Override
    public void setModifyPath(String path) {

    }

    @Override
    public String getModifyPath() {
        return null;
    }

    @Override
    public void addHeader(CharSequence name, String value) {

    }

    @Override
    public void setHeader(CharSequence name, String value) {

    }

    @Override
    public void addQueryParam(String name, String value) {

    }

    @Override
    public void addFormParam(String name, String value) {

    }

    @Override
    public void addOrReplaceCookie(Cookie cookie) {

    }

    @Override
    public void setRequestTimeout(int requestTimeout) {

    }

    @Override
    public void getFinalUrl(int requestTimeout) {

    }

    @Override
    public Request Build() {
        return null;
    }
}
